// 错误中间件，防止程序崩溃，可以打印错误
const express = require("express");

const app = express();

app.get("/home", (req, res) => {
  throw new Error("服务器内部发生了错误");
  res.send("This is home");
});
// 错误中间件放在路由之后
app.use((err, req, res, next) => {
  console.log("发生了错误:" + err.message);
  res.send("Error!" + err.message);
  next();
});

app.listen(8080, (req, res) => {
  console.log("express server running at http://127.0.0.1:8080");
});
